import { createSlice } from '@reduxjs/toolkit';
let ticketSlice = createSlice({
    name: 'ticket',
    initialState: {
        ticketName: "亲子票",
        singleNum: 3,
        quantity: 3,
        price: 39900,
        bookStartTime: "2024-11-01 00:00:00",
        bookEndTime: "2024-12-09 23:59:59",
        validStartTime: "2024-12-10 09:00:00",
        validEndTime: "2024-12-10 18:00:00",
        description: "亲子票，适合带孩子的家庭。",
        isOnSale: 0,
        tickets:[]
    },
    reducers: {
        addTicketInfo(state, actions) {
            switch (actions.payload.name) {
                case 'ticketName':
                    return { ...state, ticketName: actions.payload.value }
                case 'singleNum':
                    return { ...state, singleNum: actions.payload.value }
                case 'quantity':
                    return { ...state, quantity: actions.payload.value }
                case 'description':
                    return { ...state, description: actions.payload.value }


            }

        },
    }
    // extraReducers(builder) { // 异步的处理
    //     // 当getTest fulfilled状态时，处理
    //     builder.addCase(getTest.fulfilled, (state, { payload }) => {
    //         // 上述方法返回的结果payload
    //         state.test = payload;
    //     })
    // }
});
// 外部组件来使用的action
export const { addTicketInfo } = ticketSlice.actions;
// 默认导出是所有的reducer 供store注册这些方法
export default ticketSlice.reducer;